import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { Role } from "../../../role/Role";
import { VM } from "db://oops-framework/libs/model-view/ViewModel";
import { TableBattleConf } from "../../../common/table/TableBattleConf";
import { BattleResultType } from "./BattleEnum";

/** 战斗数据 */
@ecs.register('BattleModel')
export class BattleModelComp extends ecs.Comp {
    /** 提供MVVM组件使用的数据 */
    vm: any = {};
     /** 合成物编号 */
     get id(): number {
        return this.table.id;
    }
    set id(value: number) {
        if (this.table == null) this.table = new TableBattleConf();
        this.table.init(value);
        this.maxXiaoGuan = this.table.monsters.length;
    }
    table: TableBattleConf = null!;

      /** 当前第几小关 */
      private _xiaoguan: number = 1;
      public get xiaoguan(): number {
          return this._xiaoguan;
      }
  
      public set xiaoguan(v: number) {
          this._xiaoguan = v;
          this.vm["xiaoguan"] = v;
      }

          /** 最大小关数 */
    private _maxXiaoGuan: number = 1;
    public get maxXiaoGuan(): number {
        return this._maxXiaoGuan;
    }

    public set maxXiaoGuan(v: number) {
        this._maxXiaoGuan = v;
        this.vm["maxXiaoGuan"] = v;
    }

     /** 大关数 */
     private _daGuan: number = 7;
     public get daGuan(): number {
         return this._daGuan;
     }
 
     public set daGuan(v: number) {
         this._daGuan = v;
         this.vm["daGuan"] = v;
     }

      /** 下一大关数 */
    private _daGuanNext: number = 1;
    public get daGuanNext(): number {
        return this._daGuanNext;
    }

    public set daGuanNext(v: number) {
        this._daGuanNext = v;
        this.vm["daGuanNext"] = v;
    }

     /** 累计获得金币 */
     private _coin: number = 1;
     public get coin(): number {
         return this._coin;
     }
 
     public set coin(v: number) {
         this._coin = v;
         this.vm["coin"] = v;
     }
 
     /** 怪物总血量 */
     private _totalHp: number = 1;
     public get totalHp(): number {
         return this._totalHp;
     }
 
     public set totalHp(v: number) {
         v = Math.max(0, v);
         v = Math.min(v, this.totalHpMax);
         this._totalHp = v;
         this.vm["totalHp"] = v;
     }

       /** 怪物总血量最大值 */
    private _totalHpMax: number = 1;
    public get totalHpMax(): number {
        return this._totalHpMax;
    }

    public set totalHpMax(v: number) {
        this._totalHpMax = v;
        this.vm["totalHpMax"] = v;
    }

    /** boss倒计时 */
    private _bossTime: number = 0;
    public get bossTime(): number {
        return this._bossTime;
    }
    public set bossTime(v: number) {
        this._bossTime = v;
        this.vm["bossTime"] = v;
    }

    public battleResultType: BattleResultType = null!;

    public changeRole1: Role = null!;
    public changeRole2: Role = null!;

    vmAdd() {
        this.xiaoguan = 1;
        this.maxXiaoGuan = 7;
        this.daGuan = 1;
        this.daGuanNext = 1;
        this.coin = 0;
        this.totalHp = 0;
        this.totalHpMax = 0;
        this.bossTime = -1;
        VM.add(this.vm, "Battle");
    }

    vmRemove() {
        VM.remove("Battle");
    }

    reset(): void {
        this.id = -1;
        this._xiaoguan = 1;
        this._maxXiaoGuan = 7;
        this._daGuan = 1;
        this._daGuanNext = 1;
        this._coin = 0;
        this._totalHp = 0;
        this._totalHpMax = 0;
        this.bossTime = -1;
        this.table = null!;
        this.battleResultType = null!;
    }
}